package com.ymatou.iapi.advancewithdraw.testcase;

import java.util.HashMap;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.advancewithdraw.service.AWAccountAmendCall;
import org.json.JSONObject;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.YmtAWAccountWapper;
/**
*修改更新提前放款账户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_AWAccountAmend{
	private static AWAccountAmendCall awaccountamendCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改更新提前放款账户");
	}

	@Before
	public void caseUp() {
		awaccountamendCall=new AWAccountAmendCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(awaccountamendCall.getOpurl());
	}
	
	public static void  awaccountamendgetreturnerrcode(String ecode,String eMsg) throws Exception {
	    try {
	    	
			//获取返回报文的数据
		    String dataStr = awaccountamendCall.getReturnData();
			//返回报文断言			

			String errCode =  new JSONObject(dataStr).getString("ErrCode");
			Logger.verifyIsContains(ecode, errCode, "ErrCode");
			String errMsg =  new JSONObject(dataStr).getString("ErrMsg");
			Logger.verifyIsContains(eMsg, errMsg, eMsg);
			String body =  new JSONObject(dataStr).getString("Body");
			Logger.verifyIsNull(body, "Body为空");
			String requestUrl =  new JSONObject(dataStr).getString("RequestUrl");
			Logger.verifyIsNull(requestUrl, "RequestUrl为空");
			String Success =  new JSONObject(dataStr).getString("Success");
			Logger.verifyIsContains(false, Success, "\"Success\":false");
	    	    	    	
	    }catch (Exception e) {  
	        e.printStackTrace();
	    }  

	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Ts_AWAccountAmend_001() {
		Logger.start(true,"修改账户信用等级和action");
		try {
			//TODO 补全case代码
			
			//SQL ymtfp库  Ymt_AWAccount 
			//查询数据库Ymt_AWAccount，获得wesper的提前放款ID(account id)
			YmtAWAccountWapper ymtawaccountWapper= new YmtAWAccountWapper();
			String accountId = ymtawaccountWapper.selectBySellerId(3383).getAccountId();
			int level= ymtawaccountWapper.selectBySellerId(3383).getLevel();
			int action=ymtawaccountWapper.selectBySellerId(3383).getAction();
			
			
			
			//初始化AWAccountAmend接口的Call对象
			AWAccountAmendCall awAccountAmendCall=new AWAccountAmendCall();			
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("AWAccountId", accountId);
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    JSONObject aw=awAccountAmendCall.callAndGetReturnData(updateMap);
		    
		    //定义返回报文的accountId
		    String awAccountId=aw.getString("AWAccountId");
		    //断言返回的报文为非空
			Logger.verifyNotNull(aw, "返回报文非空");
			//断言报文返回true
			String success= aw.getString("Success");
			Logger.verifyIsContains(true, success, "\"Success\":true");
			//断言errorMsg为空
			String errMsg=aw.getString("ErrMsg");
			Logger.verifyIsNull(errMsg, "ErrorMsg等于空");
		    //断言返回的报文的accountId和更改的数据库中的accountId一致
			Logger.verifyEquals(accountId, awAccountId, "报文返回的accountId和数据库修改的accountId一致");
            //验证数据库中提前放款用户的信用等级已经修改成功
			Logger.verifyEquals(1, level, "用户的信用等级修改成功");
			//验证数据库中用户提前放款账户的状态修改成功
		    Logger.verifyEquals(20, action, "用户提前放款账户的状态修改成功");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountAmend_002() {
		Logger.start(false,"卖家用户Id为空");
		try {
			//TODO 补全case代码
			//初始化AWAccountAmend接口的Call对象
		
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("SellerId", null);
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    awaccountamendCall.callAndGetReturnData(updateMap);
		    
		    awaccountamendgetreturnerrcode("1001", "卖家用户Id不能为空");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountAmend_003() {
		Logger.start(false,"卖家用户登录名为空");
		try {
			//TODO 补全case代码
			//初始化AWAccountAmend接口的Call对象
		
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("SellerLoginId", null);
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    awaccountamendCall.callAndGetReturnData(updateMap);
		    
		    awaccountamendgetreturnerrcode("1001", "卖家用户登录名不能为空");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountAmend_004() {
		Logger.start(false,"卖家提前放款账号Id为空");
		try {
			//TODO 补全case代码
			//初始化AWAccountAmend接口的Call对象
		
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("AWAccountId", null);
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    awaccountamendCall.callAndGetReturnData(updateMap);
		    
		    awaccountamendgetreturnerrcode("1005", "卖家提前放款账号Id不能为空");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountAmend_005() {
		Logger.start(false,"提前放款账号和买手不对应");
		try {
			//TODO 补全case代码
			//初始化AWAccountAmend接口的Call对象
		YmtAWAccountWapper ymtawaccountWapper= new YmtAWAccountWapper();
			String accountId = ymtawaccountWapper.selectBySellerId(3383).getAccountId();
			
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("SellerId", 3384);
		    updateMap.put("AWAccountId", accountId);
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    awaccountamendCall.callAndGetReturnData(updateMap);
		    
		    awaccountamendgetreturnerrcode("1010", "提前放款账号和买手不对应");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P2.class})
	@TestCase
	public void Ts_AWAccountAmend_006() {
		Logger.start(false,"提前放款账号不存在");
		try {
			//TODO 补全case代码
			//初始化AWAccountAmend接口的Call对象
		
		    Map<String, Object> updateMap = new HashMap<String,Object>();
		    updateMap.put("AWAccountId", "test3f964e7a-2e38-45aa-86ae-82b23e24c167");
		    
		    //填充参数，并获取JSONObject类型的返回数据
		    awaccountamendCall.callAndGetReturnData(updateMap);
		    
		    awaccountamendgetreturnerrcode("1010", "提前放款账号不存在");
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}